const conn = require('../app/database')

class LabelService {
	async create(name) {
    const statement = `INSERT INTO label(name) VALUES (?);`
    const result = await conn.execute(statement, [name])
    return result[0]
  }

  // 因为限定了每个标签都是独一无二的
  async getLabelByName(labelName) {
    const statement = `SELECT * FROM label WHERE name = ?;`
    const result = await conn.execute(statement, [labelName])
    return result[0]
  }

	async getLabelList(offset, size) {
    const statement = `SELECT * FROM label LIMIT ?,?;`
    const result = await conn.execute(statement, [offset, size])
    return result[0]
  }
}

module.exports = new LabelService()
